<?php
class class_DuracionTurno
{
	private $_db; 
	function __construct(){
		$this->config();
	}
	
	function method_getDuracionTurno($params, $error){
		$this->_db->setQuery("SELECT min_turno FROM usuarios WHERE dni_usuario ='" . $params[0]->medico . "'");
		$this->_db->alter();
		if (mysql_error()) { $error->SetError(JsonRpcError_Unknown, (__FILE__ . " - " . (__LINE__ - 2) . ": " . mysql_error())); return $error; }
		$result = $this->_db->loadResult();
		return  $result[0]->min_turno;
    }
    
	function method_setDuracionTurno($params, $error){
		$this->_db->setQuery("UPDATE usuarios SET min_turno = '".$params[0]."' WHERE dni_usuario ='".$params[1]."' LIMIT 1");
		$this->_db->alter();
		if (mysql_error()) { $error->SetError(JsonRpcError_Unknown, (__FILE__ . " - " . (__LINE__ - 2) . ": " . mysql_error())); return $error; }
		$result = $this->_db->loadResult();
		$result = explode(":",$result[0]->min_turno);
		return $result[2];
    }
    
	function method_getMedicos($params, $error)
    {   
    	if ($params[0]->medicos)
        	$this->_db->setQuery("SELECT dni_usuario as value, CONCAT(apellido, ' - ', nombres) as label FROM usuarios WHERE cod_tipo_usuario = '3' ORDER BY label");
        else
        	$this->_db->setQuery("SELECT dni_usuario as value, CONCAT(apellido, ' - ', nombres) as label FROM usuarios WHERE dni_usuario = '" . $_SESSION['dni_usuario'] . "'");
        $this->_db->alter();
    	if (mysql_error()) { $error->SetError(JsonRpcError_Unknown, (__FILE__ . " - " . (__LINE__ - 2) . ": " . mysql_error())); return $error; }
    	
    	return $this->_db->loadResult();
    }
    
    private function config(){
		require_once("conexion.php");
		require_once("DataBase.php");
		$this->_db = new DataBase($SERVIDOR,$USUARIO,$PASSWORD,$BASE);
		mysql_query("SET NAMES utf8");
	}
}
?>